/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 16:23:10
 * @LastEditTime: 2021-08-30 16:24:23
 * @LastEditors: changqing
 * @Usage: 
 */


var { timer, interval,range } = require('rxjs'); 
var {takeWhile,map} = require('rxjs/operators');

//takeWhile需要传入一个callback function，这个callback function决定takeWhile发生事件的时机，只要这个callback funciton返回true就会持续产生事件，直到不符合条件结束

const source = interval(1000).pipe(map(data => ++data))

source.pipe(
  takeWhile(data => data < 5)
).subscribe({
  next: data => console.log(` ${data}`),
  complete: () => console.log('takeWhile complete')
});
// 1 2 3 4
// takeWhile complete